<?php

/**
 * @Author: wuchenge
 * @Date: 2020-11-30 16:52:20
 * @email: ligui0506@sina.com
 * @descript: 登录验证器
 */

namespace App\Requests;

use App\Libraries\Token;
use Illuminate\Validation\Rule;

class LoginRequest extends FormRequest
{
    public function rules()
    {
        // $admin    = Token::verifyToken();
        // $admin_id = 0;
        // if ($admin) {
        //     $admin_id = $admin['id'];
        // }
        // 默认
        return [
            'captcha'  => 'required|between:4,4',
            'username' => [
                'required',
                'min:2',
                'max:20',
                // Rule::unique('admins', 'account')->ignore($admin_id),
            ],
            'password' => 'required',
        ];
    }

    public function messages()
    {
        return [
            'username.required' => '100101',
            'username.min'      => '100102',
            'username.max'      => '100103',
            // 'username.unique'   => '100104',
            'captcha.required'  => '100105',
            'captcha.between'   => '100106',
            'password.required' => '100107',
        ];
    }

    public $scene = [
        'admin.login.index' => ['password', 'username'],
    ];
}
